package main

import (
	"jinquan.supor.com/common"
	"jinquan.supor.com/samples/mongo/docs"
	"strings";"fmt"
)

func main() {
	//Pod 内部域名
	/*
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongo-0.mongo.mongo-ns.svc.cluster.local:27017,
											      mongo-1.mongo.mongo-ns.svc.cluster.local:27017,
												  mongo-2.mongo.mongo-ns.svc.cluster.local:27017/?slaveOk=true`, 
												  "secondary")
	*/
	clnt, _ := common.Mongo_ServerConn(`mongodb://mongodb.jinquan.svc.cluster.local:27017`, "primary")
	
	var docArr = testdoc.GenData01DocArray(1)
	k1 := "Name";v1 := common.IfVal_string(docArr[0], k1)
	k2 := "FloatVal";v2 := common.IfVal_float32(docArr[0], k2)

	fmt.Printf("%s: %s\t%s: %f\n", k1,v1,k2,v2)
	common.Mongo_CollAddDoc(clnt, "db_5", "coll_1", docArr[0])

	/* 获取返回Document的某个字段数据 */
	var docSt_X = testdoc.AllocData01Doc()
	fmt.Printf("docSt_X ->> %v\n", docSt_X[0])
	
	objX := common.F1S1KV{ 
		Kf:k2, 
		Vf:v2, 
		Ks:k1, 
		Vs:v1,
	}

	docSt_X[0],_ = objX.Doc(clnt, "db_5", "coll_1", docSt_X[0])
	
	m := common.If2Map(docSt_X[0])	
	kk1 := strings.ToLower("Name") //从MongoDB取出来的Key都是小写
	fmt.Printf("Get Document data ->> %s: %s\n", kk1, m[kk1])
	kk2 := strings.ToLower("FloatVal") //从MongoDB取出来的Key都是小写
	fmt.Printf("Get Document data ->> %s: %s\n", kk2, m[kk2])
	
}